package com.yenlien.traceyun.control.service.rest;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.control.bean.RestURL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-07-21
 * @description:
 **/

@Service
public class AppRestService {
    @Autowired
    private RestService restService;

    /**
     * 注册到用户中心
     *
     * @param appId
     * @param appName
     * @param appType
     * @param appCode
     * @return
     */
    public JSONObject register(String appId, String appName, String appType, String appCode) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("appId", appId);
        jsonObject.put("appName", appName);
        jsonObject.put("appType", appType);
        jsonObject.put("appCode", appCode);
        return restService.postJson(RestURL.USERCENTER + "app/register", jsonObject);
    }

    /**
     * 获取产品
     *
     * @return
     */
    public JSONObject list() {
        return restService.getJson(RestURL.USERCENTER + "app/list");
    }

    /**
     * 更改应用状态
     *
     * @param id
     * @param used
     * @return
     */
    public JSONObject used(String id, boolean used) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", id);
        jsonObject.put("used", used);
        return restService.postJson(RestURL.USERCENTER + "app/used", jsonObject);
    }

    /**
     * 获取自定义产品下拉
     *
     * @return
     */
    public JSONObject findAll() {
        return restService.getJson(RestURL.USERCENTER + "app/customApp/findAll");
    }

    /**
     * 获取自定义产品列表
     *
     * @return
     */
    public JSONObject findCustomApp(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "app/list/customapp", jsonObject);
    }

    /**
     * 根据customerAppId获取版本
     *
     * @param customAppId
     * @return
     */
    public JSONObject findCustomAppVersion(String customAppId) {
        return restService.getJson(RestURL.USERCENTER + "app/list/customappversion/" + customAppId);
    }

    /**
     * @param params
     * @param files
     * @return
     */
    public JSONObject createCustomApp(Map<String, Object> params, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "app/create/customapp", params, files);
    }

    public JSONObject createCustomApp2(Map<String, Object> params) {
        return restService.postJson(RestURL.USERCENTER + "app/create/customapp2", params);
    }


    /**
     * 加载应用列表
     *
     * @return
     */
    public JSONObject listallCustomApp() {
        return restService.getJson(RestURL.USERCENTER + "app/listall/customapp");
    }

    public JSONObject createCustomAppVersion(JSONObject params) {
        return restService.postJson(RestURL.USERCENTER + "app/create/customappversion", params);
    }


    public JSONObject findByCustomAppId(String id) {
        return restService.getJson(RestURL.USERCENTER + "app/list/customappversion/" + id);
    }

    /**
     * 根据自定义版本Id查询自定义产品
     *
     * @return
     */
    public JSONObject findCustomAppVersionId(String id) {
        return restService.getJson(RestURL.USERCENTER + "app/findCustomAppVersionId/" + id);
    }

    /**
     * 根据公司id和APPID查询自定义产品
     *
     * @return
     */
    public JSONObject findCompanyCustomAppVersion(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "app/findCompanyCustomAppVersion", jsonObject);
    }


    /**
     * 根据公司id查询自定义产品
     *
     * @return
     */
    public JSONObject loadbycompanyId(String id) {
        return restService.getJson(RestURL.USERCENTER + "app/loadbycompanyId/" + id);
    }

}
